<template>
	<view class="login_index">
		<tn-toast ref="toast"></tn-toast>
		<tn-button width="700rpx" size="lg" backgroundColor="#2fad6a" fontColor="#ffffff"
			@click="sures()">授权登录</tn-button>
		<tn-modal @click="sure()" :zIndex="999999" v-model="show" :title="title" :content="content"
			:button="button"></tn-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				scene: '',
				show: false,
				title: '授权确认',
				content: '确认之后即可进行授权登录',
				button: [{
						text: '取消',
						backgroundColor: '#E6E6E6',
						fontColor: '#333333',
						plain: true,
						shape: 'round'
					},
					{
						text: '确定',
						backgroundColor: 'tn-bg-indigo',
						fontColor: '#FFFFFF'
					}
				],
			}
		},
		onLoad(query) {

			if (query) {
				this.scene = query.scene;

			}

		},
		methods: {
			sures() {
				this.show = true;
			},
			sure(index) {
				if (index.index == 0) {
					this.show = false;
				} else {

					this.send();

				}


			},
			send() {
				uni.login({
					provider: 'weixin',
					success: async (loginRes) => {

						this.sessionId = loginRes.code;
						console.log(this.scene,'this.scene');
						console.log(this.sessionId,'this.sessionId');
						try {
							const url = '/portal/r/w'; // 替换为你的 API 地址
							const params = {
								// 构造你的请求参数
								scene: this.scene,
								cmd: 'com.apps.sfeg.portal.loginOk',
								wxCode: this.sessionId
							};

							// 发送 GET 请求
							const response = await this.$get(url, params);

							console.log(response, 'response')
							if (response.data == 'userErr') {
								this.show = false;
								this.$refs.toast.show({

									content: response.msg,

									duration: 2000 // 显示时长 2000ms
								});
								setTimeout(function() {
									uni.navigateTo({
										url: '../../pages/loginIndex/loginIndex'
									});
								}, 2000);
							} else if (response.data == 'sucess') {
								this.show = false;
								this.$refs.toast.show({

									content: '授权成功',

									duration: 2000 // 显示时长 2000ms
								});
								setTimeout(function() {
									uni.navigateTo({
										url: '../../pages/loginIndex/loginIndex'
									});
								}, 2000);
							}else if (response.data == 'openidErr'){
								this.show = false;
								this.$refs.toast.show({
								
									content: response.msg,
								
									duration: 2000 // 显示时长 2000ms
								});
							
							}



						} catch (error) {
							// 处理请求失败的逻辑
							console.error('请求失败', error);
						}


					},
					fail: function(err) {}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.login_index {
		display: flex;
		align-items: center;
		/* 垂直居中 */
		justify-content: center;
		/* 水平居中 */
		height: 100vh;
		background-image: url('https://srm.sfeg.cc/portal/apps/com.awspaas.user.apps.sfeg.srm.contractworkers/img/Shanghai.jpg');
		/* 设置背景图的显示方式，可以根据需要调整 */
		background-size: cover;
		background-position: center;

		.login_index_box {
			margin-top: 186rpx;

			.login_index_logo {
				text-align: center;
			}

			.login_index_logo1 {
				text-align: center;
				margin-top: 35rpx;
				font-size: 46rpx;
				font-family: 'HanYiZongYi';
				font-weight: 700;
			}
		}

		.login_index_btn {
			margin-top: auto; // 将其推到底部
			text-align: center;
			margin-bottom: 46rpx;

			button {
				// padding: 21rpx 197rpx;
				font-family: PingFang SC;
				font-weight: bold;
				font-size: 40rpx;
				color: #FFFFFF;
				background: linear-gradient(90deg, #3A84FD 0%, #536AFF 100%);
				border-radius: 40rpx;
				margin: 0 78rpx;
			}
		}

		.login_index_agree {
			font-family: Microsoft YaHei;
			font-weight: 400;
			font-size: 28rpx;
			display: flex;
			justify-content: center;
			text-align: center;
			color: #333333;
			margin-bottom: 97rpx;
		}
	}
</style>